package thread;

/**
 * Created with IntelliJ IDEA
 * Description：join控制结束时序
 * User：chenshu
 * Date：2023-11-02
 * Time：11:03
 */
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        System.out.println("main运行中...");
        Thread t1 = new Thread(() -> {
            System.out.println("t1运行中...");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t1结束");
        });

        Thread t2 = new Thread(() -> {
            System.out.println("t2运行中...");
            try {
                t1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t2结束");
        });

        t1.start();
        t2.start();
        t2.join();
        System.out.println("main结束");
    }
}
